package jmu.cze.service.impl;

import jmu.cze.mapper.AirportMapper;
import jmu.cze.mapper.CityMapper;
import jmu.cze.mapper.CountryMapper;
import jmu.cze.mapper.TerminalMapper;
import jmu.cze.pojo.Airport;
import jmu.cze.pojo.City;
import jmu.cze.pojo.Country;
import jmu.cze.pojo.Terminal;
import jmu.cze.service.LocationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class LocationServiceImpl implements LocationService {
    private CountryMapper countryMapper;
    private CityMapper cityMapper;
    private AirportMapper airportMapper;
    private TerminalMapper terminalMapper;

    @Resource(name = "countryMapper")
    public void setCountryMapper(CountryMapper countryMapper) {
        this.countryMapper = countryMapper;
    }

    @Resource(name = "cityMapper")
    public void setCityMapper(CityMapper cityMapper) {
        this.cityMapper = cityMapper;
    }

    @Resource(name = "airportMapper")
    public void setAirportMapper(AirportMapper airportMapper) {
        this.airportMapper = airportMapper;
    }

    @Resource(name = "terminalMapper")
    public void setTerminalMapper(TerminalMapper terminalMapper) {
        this.terminalMapper = terminalMapper;
    }

    @Override
    public Map<Integer, Country> selectAllCountries() {
        return countryMapper.selectAllCountries();
    }

    @Override
    public Map<String, City> selectAllCities() {
        return cityMapper.selectAllCities();
    }

    @Override
    public List<Airport> selectAllAirports() {
        return airportMapper.selectAllAirports();
    }

    @Override
    public boolean deleteCountryByID(int countryID) {
        return countryMapper.deleteCountryByID(countryID) == 1;
    }

    @Override
    public boolean insertCountry(Country country) {
        return countryMapper.insertCountry(country) == 1;
    }

    @Override
    public boolean updateCountry(Country country) {
        return countryMapper.updateCountry(country) == 1;
    }

    @Override
    public boolean deleteCityByID(String cityID) {
        return cityMapper.deleteCityByID(cityID) == 1;
    }

    @Override
    public boolean insertCity(City city) {
        return cityMapper.insertCity(city) == 1;
    }

    @Override
    public boolean updateCity(City city) {
        return cityMapper.updateCity(city) == 1;
    }

    @Override
    public boolean deleteAirportByID(String airportID) {
        return airportMapper.deleteAirportByID(airportID) == 1;
    }

    @Override
    public boolean insertAirport(Airport airport) {
        return airportMapper.insertAirport(airport) == 1;
    }

    @Override
    public boolean updateAirport(Airport airport) {
        return airportMapper.updateAirport(airport) == 1;
    }

    @Override
    public boolean deleteTerminalByID(int terminalID) {
        return terminalMapper.deleteTerminalByID(terminalID) == 1;
    }

    @Override
    public boolean insertTerminal(Terminal terminal) {
        return terminalMapper.insertTerminal(terminal) == 1;
    }

    @Override
    public boolean updateTerminal(Terminal terminal) {
        return terminalMapper.updateTerminal(terminal) == 1;
    }
}
